//682.棒球比赛
//https://leetcode.cn/problems/baseball-game
class Solution {
public:
    int calPoints(vector<string>& operations) {
        stack<int> st;

        for(string& s:operations)
        {
            if(s[0] == 'D') st.push(st.top()*2);
            else if(s[0] == 'C') st.pop();
            else if(s[0] == '+')
            {
                int x  = st.top();
                st.pop();
                int y = st.top();
                st.push(x);
                st.push(x+y);
            }
            else st.push(stoi(s));
        }
        int ret = 0;
        while(st.size())
        {
            ret += st.top();
            st.pop();
        }
        return ret;
    }
};